// OSS 文件下载
import { ElMessage } from "element-plus";
import createOssClientTemp from "./initOss.ts";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const OssDownloadFileUrl: Promise<string> = async (fileName: string) => {
  const client = await createOssClientTemp();
  return new Promise((resolve, reject) => {
    try {
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-expect-error
      const url = client.signatureUrl(fileName, {
        response: {
          "content-disposition": `attachment; filename=${encodeURIComponent(fileName)}`
        },
        expires: 3600
      });
      resolve(url);
    } catch (e) {
      ElMessage.error("阿里云 oss 下载 失败");
      reject(e);
    }
  });
};
export default OssDownloadFileUrl;
